{include file="public/header" /}
<style>
    .layui-form-label{width: 180px;margin-left: -55px}
</style>
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>新增轮播</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">轮播名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_name" lay-verify="required" placeholder="轮播名称" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">图片：</label>
                            <input type="hidden" name="banner_image" id="lay-img" lay-verify="image">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览：
                                    <div class="layui-upload-list" id="lay-list">
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6 form-group">
                            <label class="layui-form-label">轮播状态：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="banner_status" value="1" class="layui-input" title="上架" checked/>
                                <input type="radio" name="banner_status" value="2" class="layui-input" title="下架"/>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md6">
                            <label class="layui-form-label">排序：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_sort" lay-verify="required" placeholder="排序，值越大越靠前" class="layui-input" oninput="value=value.replace(/[^\d]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">轮播详情_英文：</label>
                            <div class="layui-input-block" id="LAY_editor_en" lay-verify="editor">

                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">轮播详情_西班牙：</label>
                            <div class="layui-input-block" id="LAY_editor_es" lay-verify="editor">

                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">轮播详情_葡萄牙：</label>
                            <div class="layui-input-block" id="LAY_editor_tp" lay-verify="editor">

                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

{include file="public/footer" /}
<script>
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""}); // 图片

    // 富文本
    var editor_en = wk.wang({elem:'#LAY_editor_en'}); // 英文
    var editor_es = wk.wang({elem:'#LAY_editor_es'}); // 西班牙
    var editor_tp = wk.wang({elem:'#LAY_editor_tp'}); // 葡萄牙

    layui.use(['form','upload','layedit','laydate'], function() {
        var form = layui.form;
        form.verify({
            image:[/\S/,'请上传图片'],
            editor:function(value,item){
                if(!editor_en.txt.text()){
                    return '请填写英文轮播详情';
                }
                if(!editor_es.txt.text()){
                    return '请填写西班牙语轮播详情';
                }
                if(!editor_tp.txt.text()){
                    return '请填写葡萄牙语轮播详情';
                }
            }
        });
        // 创建订单
        form.on('submit(component-form-element)', function (data) {
            data.field.banner_detail_en = editor_en.txt.html();
            data.field.banner_detail_es = editor_es.txt.html();
            data.field.banner_detail_tp = editor_tp.txt.html();
           $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('bannerAdd')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                       wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            });
        });

    });
</script>

</body>
</html>